﻿namespace Web.Control.WWW.Session
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Model.WWW_User.Teach;
    using BLF.WWW_User.Teach;
    using Lx.Web.Common.ControlsUI;
    using System.Collections.Generic;
    using System.Collections;
    using Model.WWW_User.User;
    public class sessionState0 : BaseControl
    {
        protected string Memberno = "";
        protected List<string> srlist;
        protected long sid = -1;
        protected SessionsModel sm = null;
        protected string IMAccount = "";
        protected string Timezone = "";
        protected DateTime dt = new DateTime();
        protected TeachModel tm = new TeachModel();
        protected List<LessonModel> lelist;
        protected UserProfileModel um = new UserProfileModel();
        protected Repeater reless;
        protected List<string> srlist2 = new List<string>();
        private int le = 0;
        protected bool isshow = false;
        protected override void OnLoad(EventArgs e)
        {
            Memberno = HttpContext.Current.User.Identity.Name;
            ArrayList arrylist = new ArrayList();
            if (Memberno == "")
            {
                Page.Response.Redirect("/user/login.htm?ReturnUrl=" + Page.Request.Url.AbsoluteUri);
                return;
            }
            if (!string.IsNullOrEmpty(Request["sid"]))
            {
                long.TryParse(Request["sid"], out sid);
            }
            else
            {
                Response.End();
            }
          
                arrylist = Teach.GetSessionsState3(sid, Memberno);
                if (arrylist != null && arrylist.Count > 0)
                {
                    sm = arrylist[0] as SessionsModel;
                    IMAccount = (string)arrylist[1];
                    tm = arrylist[2] as TeachModel;
                    srlist = arrylist[3] as List<string>;
                    um = arrylist[4] as UserProfileModel;
                    lelist = arrylist[5] as List<LessonModel>;
                    if (sm.SessionID == sid) { isshow = true; }
                    if (isshow)
                    {
                        if (reless != null)
                        {
                            reless.DataSource = lelist;
                            reless.DataBind();
                        }
                        Timezone = um.Timezone == "" ? "0" : um.Timezone;
                        dt = Teach.ConvertTime(sm.StartDate, sm.StartTime, Timezone);
                        le = srlist.Count;
                        srlist2.Add(um.IM1Account);
                        srlist2.Add(um.IM2Account);
                        srlist2.Add(um.IM3Account);
                        srlist2.Add(um.IM4Account);
                        srlist2.Add(um.IM5Account);
                        srlist2.Add(um.IM6Account);
                        Response.Write("<script> var _Te_List=new Array();var _St_List=new Array();");
                        for (int i = 0; i < 6; i++)
                        {
                            Response.Write("_St_List[" + i + "]='" + srlist2[i] + "';");
                            Response.Write("_Te_List[" + i + "]='" + srlist[i] + "';");
                        }
                        Response.Write("</script>");
                    }
                   
                }
                else
                {
                    Response.End();
                }
                
            base.OnLoad(e);
        }
        protected string GetLang(string l1, string l2, string l3, string l4,string l5)
        {
            string va = "";
            if (l1 != "")
            {
                va += "<option value='" + l1 + "' " + (l5==l1?"selected=\"selected\"":"")+ " >" + BLF.StaticData.GetLanguageText(l1) + "</option>";
            }
            if (l2 != "")
            {
                va += "<option value='" + l2 + "'  " + (l5 == l2 ? "selected=\"selected\"" : "") + " >" + BLF.StaticData.GetLanguageText(l2) + "</option>";
            }
            if (l3 != "")
            {
                va += "<option value='" + l3 + "'   " + (l5 == l3 ? "selected=\"selected\"" : "") + ">" + BLF.StaticData.GetLanguageText(l3) + "</option>";
            }
            if (l4 != "")
            {
                va += "<option value='" + l4 + "'  " + (l5 == l4 ? "selected=\"selected\"" : "") + " >" + BLF.StaticData.GetLanguageText(l4) + "</option>";
            }
            return va;

        }
        protected string GetIm()
        {
            string va = "";
            for (int i = 0; i < le; i++)
            {
                if (srlist[i].ToString().Trim() != "")
                {
                    va += "<option value='" + (i + 1) + "'" + (int.Parse(sm.TeachTool) - 1 == i ? "selected=\"selected\"" : "") + " >" + Getimtx(i+1) + "</option>";
                }
            }
            return va;
        }
        private string Getimtx(int i)
        {
            return BLF.WWW_User.Users.User.GetIMToolText(i.ToString());
        }
        protected string GetTedate(int let)
        {
            string va = "";
            DateTime dttt = DateTime.UtcNow.AddMinutes(double.Parse(Timezone));
            for (int i = 0; i <= let; i++)
            {
                DateTime dtt = dttt.AddDays((double)i);
                va += "<option value='" + dtt.ToString("yyyyMMdd") + "' " +( dtt.ToString("yyyyMMdd") == dt.ToString("yyyyMMdd") ? "selected=\"selected\"" : "" )+ ">" + dtt.ToString(TimeToString2,new System.Globalization.CultureInfo(Lx.Web.Common.UI.Globals.Language)) + "</option>";
            }
            return va;
        }
        
    }
}